package com.codebuffer.nowcoder;

import java.util.Arrays;

public class MinNumberInRotateArray {

    public static void main(String[] args) {
        int [] array = {3,4,5,1,2};
        System.out.println(minNumberInRotateArray(array));
    }
    public static int minNumberInRotateArray(int [] array) {
        if(array.length==0){
            return 0;
        }
        int x=0;
        int y=array.length-1;
        while (x<y){
            if(array[x]<array[y]){
                return array[x];
            }
            int mid = (x+y)>>1;
            if (array[mid] > array[y]) {
                x=mid+1;
            }else if(array[mid] < array[y]){
                y=mid;
            }else {
                x++;
            }
        }
        return array[x];
    }
}
